package jp.ne.ayamesoft.ayamevoicedialer;

import android.app.PendingIntent;
import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.RemoteViews;

public class AyameVoiceDialerService extends Service {

	private static final String ACTION_BUTTON_CLICK =
        "jp.ne.ayamesoft.ayamevoicedialer.AyameVoiceDialerService.ACTION_BUTTON_CLICK";

	@Override
	public void onStart(Intent intent, int startId) {
		
		// TODO Auto-generated method stub
		super.onStart(intent, startId);
		AyameLOG.D("Service onStart:" + getPackageName());
		AppWidgetManager manager = AppWidgetManager.getInstance(this);
	    RemoteViews view = new RemoteViews(getPackageName(), R.layout.dialwidget);
	    if (ACTION_BUTTON_CLICK.equals(intent.getAction())) {
		    AyameLOG.D("Service ACTION_BUTTON_CLICK getAction:" + intent.getAction());
	        button_Clicked(view);
	    }
	    Intent newintent = new Intent();
	    newintent.setAction(ACTION_BUTTON_CLICK);
	    PendingIntent pending = PendingIntent.getService(this, 0, newintent, 0);
	    view.setOnClickPendingIntent(R.id.dialimgbtn_id, pending);
	    ComponentName widget = new ComponentName(this, AyameVoiceDialerWidget.class);
	    manager.updateAppWidget(widget, view);
	    
	}

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	public void button_Clicked(RemoteViews view){
		AyameLOG.D("Service button_Clicked");
	    Intent intent = new Intent(this,AyameVoiceDialerSend.class);
	    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	    startActivity(intent);
	}

}
